<template>
  <header>
    <div class="logo">
      <img src="@/assets/IMAGES/icon_logo.png" alt="" />
    </div>
    <div class="identity" @click.stop="setting">
      <div class="head">
        <img src="@/assets/IMAGES/icon_head.png" alt="" />
      </div>
      <div class="info">
        <h3>管理员</h3>
        <p>{{username}}</p>
      </div>
      <div class="to-down">
        <img src="@/assets/IMAGES/icon_todown.png" alt="" />
      </div>
      <!--退出-->
      <ul class="logout animated fadeInDown" v-if="isLogout">
        <li @click="logout">退出</li>
      </ul>
    </div>
  </header>
</template>
<script>
export default {
  name: "headerBar",
  data() {
    return {
      isLogout: false,
      username:""
    };
  },
  methods: {
    logout() {
      this.$emit("changeLogin");
    },
    setting() {
      this.isLogout = true;
    },
  },
  created(){
    if(sessionStorage.getItem('loginInfo')){
       this.username=JSON.parse(sessionStorage.getItem('loginInfo')).username;
    }
  },
  mounted() {
    document.addEventListener("click", () => {
      this.isLogout = false;
    });
  },
};
</script>
<style lang="scss" scoped>
header {
  position: relative;
  height: 10vh;
  display: flex;
  padding: 0 40px;
  align-items: center;
  box-sizing: border-box;
  background: #476ecf;
  justify-content: space-between;
  border-radius: 0px 0px 16px 16px;
  .logo {
    width: 140px;
    height: 60px;
    img {
      width: auto;
    }
  }
  .identity {
    position: relative;
    display: flex;
    align-items: center;
    cursor: pointer;
    .head {
      height: 48px;
      width: 48px;
      margin-right: 20px;
    }
    .info {
      flex: 1;
      font-family: PingFangSC-Medium, PingFang SC;
      color: #ffffff;
      h3 {
        font-size: 22px;
        font-weight: 500;
      }
      p {
        font-size: 16px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
      }
    }
    .to-down {
      margin-left: 20px;
      height: 10px;
      width: 18px;
    }
    .logout {
      position: absolute;
      top: 60px;
      right: 0;
      width: 140px;
      background: #ffffff;
      text-align: center;
      box-shadow: 0px 0px 8px 0px rgba(71, 110, 207, 0.15);
      border-radius: 8px;
      li {
        height: 48px;
        line-height: 48px;
        font-size: 18px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #666666;
      }
    }
  }
}
</style>